package com.java1234.util;

import java.io.File;
import java.sql.Connection;
import java.util.List;

import com.java1234.dao.MessageDao;
import com.java1234.model.Message;

import net.sf.json.JSONObject;

public class PoiExcelDao {

	
	
	public static void main(String[] args) {
		ImportExcelUtils importE = new ImportExcelUtils();
		String fileUrl="D:\\eclipse-ee\\workspace\\.metadata\\.plugins\\org.eclipse.wst.server.core\\tmp0\\wtpwebapps\\StudentInfoManage\\upload\\2.xls";
		List<List<String>> sheetList = importE.getContent(fileUrl);
		List<String> rowContents=null;
		Message message = new Message();
		for(int i = 1;i< sheetList.size(); i++ ){
			rowContents = sheetList.get(i);
			
			String name = rowContents.get(0);
			String m_desc = rowContents.get(1);
			message.setName(name);
			message.setM_desc(m_desc);
			System.out.println("序号"+message.getName()+"名字"+message.getM_desc());
			
			DbUtil dbUtil=new DbUtil();
			MessageDao messageDao=new MessageDao();
			Connection con=null;
			try{
				con=dbUtil.getCon();
				int saveNums=0;
				JSONObject result=new JSONObject();
					saveNums=messageDao.messageAdd(con, message);

				if(saveNums>0){
					result.put("success", "true");
				}else{
					result.put("success", "true");
					result.put("errorMsg", "添加失败");
				}
			}catch(Exception e){
				e.printStackTrace();
			}finally{
				try {
					dbUtil.closeCon(con);
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		
		File file = new File(fileUrl);
		file.delete();
	}
}
